package com.crm.service.impl;

import com.crm.entity.SysUser;
import com.crm.dto.UserLoginDto;
import com.crm.exception.BusinessException;
import com.crm.mapper.SysLoginMapper;
import com.crm.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysLoginServiceImpl implements SysLoginService {
    @Autowired
    private SysLoginMapper sysLoginMapper;
    //登录
    @Override
    public SysUser login(UserLoginDto userLoginDto) {
        //验证账号在数据库中是否存在
        SysUser sysUser =sysLoginMapper.findByUsername(userLoginDto.getUserName());
        if (sysUser==null){
            throw new BusinessException("账号不存在");
        }
        //验证密码是否正确
        if (userLoginDto.getPassword().equals(sysUser.getPassword())){
            throw new BusinessException("密码错误");
        }
        //验证账号状态是否启用
        if (sysUser.getStatus().equals(1)){
            throw new BusinessException("账号状态异常");
        }
        return sysUser;
    }
}
